package concur;

abstract class SaleTickets implements Runnable{
	private int ticketCount = 10;// 总的票数
	
	public synchronized boolean sellTicket(){
		
		synchronized(this) {   //this作为锁
			//临界区 共享数据是ticketCount
         if (ticketCount > 0){
             ticketCount--;
             
              System.out.println(Thread.currentThread().getName() + "正在卖票,还剩" + ticketCount + "张票");
              return true;
          }else {           
             System.out.println("票已经卖完！");  
         	 return false;
      }
	}
}
	public synchronized int readTicket() {
		
		return ticketCount;
	
	

}

//static public void main(String[] ss) {
	//SaleTickets t = new SaleTickets();
	//new Thread(t).start();
	
	//new Thread(t).start();


//}

//public void run() {
	//while(sellTicket()) {
		
	//}
	
}

//}